package cn.stylefeng.guns.modular.ws.sso.action;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;

/**
 * @Author:
 * @Date: 2019/1/9 11:12
 */
public class GetHrmInfoTest {
    public static void main(String[] args) throws Exception {
        HttpUrlConnectionTest t = new HttpUrlConnectionTest() ;
        String login_url = "http://127.0.0.1/rest/login?username=admin&password=111111";

        Map<String, String> header =t.splid(t.HEADER);
        String result = t.sendPost(login_url,"",header);
        System.out.println(result) ;

        String url = "http://127.0.0.1/rest/mgr/list";
        URL serverUrl = new URL(url);
        HttpURLConnection connection = (HttpURLConnection) serverUrl.openConnection();
        connection.setRequestMethod("GET");

        if (connection.getResponseCode() != 200) {
            throw new RuntimeException(
                    "HTTP GET Request Failed with Error code : "
                            + connection.getResponseCode());
        }
        BufferedReader responseBuffer = new BufferedReader(
                new InputStreamReader((connection.getInputStream())));
        String output;
        System.out.println("Output from Server:  \n");
        while ((output = responseBuffer.readLine()) != null) {
            System.out.println(output);
        }
        connection.disconnect();
    }
}